$(function () {
    //上传头像
    layuiFunciton.uploadFile({
        elem: '.userFaceBtn',
        url:  layuiFunciton.URL + '/file/fileUpload/uploadFile?code=image&isShrink=false',
        done: function(res, index, upload){
            $('#userFace').attr('src',res.data[0].relativePath);
            $("#employeeHead").val(res.data[0].relativePath);
        }
    });

    layuiFunciton.ajaxRequest({
        url:  layuiFunciton.URL + '/sign/getCurrentUserInfo',
        method: 'get',
        success: function(data){
            $("#id").val(data.id);
            $("#account").val(data.account); //用户名
            $("#roleNames").val(data.roleNames); //当前角色
            $("#name").val(data.name); //真实姓名
            $("#description").val(data.description); //自我评价
            $("#employeeHead").val(data.employeeHead);
            $('#userFace').attr('src',data.employeeHead);//图片
            var roleList = data.sysRoleList;
            var roleHtml='';
                if(data.roleId==0)
                    roleHtml+='<input type="radio" name="roleId" value="0" title="全部" checked="">';
                else
                    roleHtml+='<input type="radio" name="roleId" value="0" title="全部">';
            $.each(roleList,function (index,obj) {
                if(data.roleId==obj.id)
                    roleHtml+='<input type="radio" name="roleId" value="'+obj.id+'" title="'+obj.roleName+'" checked="">';
                else
                    roleHtml+='<input type="radio" name="roleId" value="'+obj.id+'" title="'+obj.roleName+'">';
            });
            $("#defualtRole").html(roleHtml);
        }
    });

    //提交表单
    layuiFunciton.formSubmit({
        filterName:'changeUser',
        url:  layuiFunciton.URL + '/sysUser/updateSysUser',
        formId:'userForm',
        success:function (data) {
            if(data==1){
                layuiFunciton.success("修改成功！",function () {
                    window.location.reload();
                })
            }
        }
    });
    
    $("#reset").click(function () {
        $("#name").val(""); //真实姓名
        $("#description").val(""); //自我评价
    });
});